<template>
	<view class="content">
		<nav-bar leftType="1" leftText="学习备考"></nav-bar>
		<view class="tab">
			<view v-for="(item,index) in tabList" :key="index" class="item" :class="{'on': tabIndex==index}" @click="tabClick(index)">{{item}}</view>
		</view>
		<view v-if="[1,2].includes(tabIndex)" class="search">
			<image class="icon" src="/static/image/search-icon.png" mode="aspectFit"></image>
			<input type="text" placeholder="搜索考试通知信息" v-model="title" @blur="search" />
		</view>
		<view v-if="tabIndex===0">
			<view class="banner">
				<swiper class="swiper" circular @change="swiperChange" :interval="2000" :indicator-dots="true" indicator-color="rgba(247,248,250,.3)" indicator-active-color="#F7F8FA" :autoplay="true">
					<swiper-item v-for="(item,index) in banner" :key="index" @click="bannerClick(item)">
						<view class="swiper-item"><image class="img" :src="item.file" mode="aspectFit"></image></view>
					</swiper-item>
				</swiper>
			</view>
			<view class="pro-list">
				<view class="item" v-for="(item,index) in COURSELIST" :key="index" @click="goCuDetail(item.id)">
					<view class="left">
						<image class="img" :src="item.photo" mode="aspectFit"></image>
					</view>
					<view class="info">
						<view class="title">{{item.title}}</view>
						<view class="t1">陶老师护考</view>
					</view>
				</view>
			</view>
		</view>
		<view class="oldlist oldlist1" v-if="tabIndex===1">
			<view class="item" v-for="(item,index) in configByList" :key="index+'a'" @click="goDetail2(item)">
				<view class="title">{{item.configName}}
					<view class="status status1" v-if="item.configType=='Y'">（进行中）</view>
					<view class="status" v-else-if="item.configType=='E'">（已结束）</view>
					<view class="status" v-else>（未开始）</view>
				</view>
				<view class="info"><text>{{item.v1}}</text></view>
				<view class="info" v-if="item.remark"><text>{{item.remark}}</text></view>
				<view class="right">
					<view v-if="[15,16].includes(item.configId)" class="right-name">如何报名</view>
					<view v-if="item.configId==18" class="right-name">如何打印</view>
					<view class="iconfont icon-xiangxia-copy"></view>
				</view>
			</view>
			<view class="base-no-data" v-if="!configByList || configByList.length===0">
				<image class="icon" src="/static/image/no-data.png" mode="aspectFit"></image>
				<view class="msg">暂无考试动态信息~ </view>
			</view>
		</view>
		<view class="oldlist" v-else-if="tabIndex===2" :class="{'base-no-data': !list2.records || list2.records.length===0}">
			<view class="item" v-for="(item,index) in list2.records" :key="index+'a'" @click="goDetail(item)">
				<view class="title">{{item.title}}</view>
				<view class="info">
					<view></view>
					<view>{{item.updatedAt}}</view>
				</view>
			</view>
			<view class="base-no-data" v-if="!list2.records || list2.records.length===0">
				<image class="icon" src="/static/image/no-data.png" mode="aspectFit"></image>
				<view class="msg">暂无备考复习信息~ </view>
			</view>
		</view>
	</view>
</template>

<script>
	import {banner,getConfigById,exams,courseListV3,courseDetail} from "@/api/index.js"
	export default {
		data() {
			return {
				tabList: ['视频讲解','考试流程','备考复习'],
				tabIndex: 0,
				swiperIndex: 0,
				banner: [],
				configByList: [],
				list2: [],
				title: '',
				COURSELIST: [],
			}
		},
		onLoad() {
			this.getBanner();
			this.getConfigById();
			this.getExams('2');//备考复习
			this.courseListV3();
		},
		methods: {
			goCuDetail(id){
				this.courseDetail(id);
			},
			courseDetail(id){
				courseDetail({id}).then(res=>{
					for(let item of res?.data?.cates){
						item.showList=false;
					}
					uni.navigateTo({
						url: `/pagesD/webView/curriculumPlay?id=${res?.data?.cates?.[0]?.id}`,
					})
					this.$store.commit('set', ['examObj',res?.data]);
				})
			},
			courseListV3(){
				courseListV3({
					page: 1,
					size: 100,
					type: '1',
					platform: '1',//显示平台：1-微信，2-抖音
					amount: 0,
					window: '1',
				}).then(res=>{
					this.COURSELIST=res?.data || []
				})
			},
			search(){
				if(this.tabIndex===2){
					this.list2=[];
					this.getExams('2');//备考复习
				}
			},
			getConfigById(){
				getConfigById().then(res=>{
					if(res.data?.length>0){
						const index=res.data.findIndex(i=>i.configId==22);
						const [item]=res.data?.splice(index,1);
						res.data?.splice(2,0,item);
						this.configByList=res.data;
					}
				})
			},
			getExams(type){
				exams({
					type,
					title: this.title,
					page: 1,
					size: 100
				}).then(res=>{
					console.log(res,'--36')
					this[`list${type}`]=res.data;
				})
			},
			tabClick(index){
				this.tabIndex=index;
			},
			swiperChange(e){
				this.swiperIndex=e.detail.current;
			},
			getBanner(){
				banner().then(res=>{
					this.banner=res.data.filter(item=>item.show!='2');
				})
			},
			goDetail(item){
				console.log(item,'-------146')
				if(item.show=='2'){//自定义内容
					this.$store.commit('set', ['noticeDetail',item]);
					uni.navigateTo({
						url: `/pagesD/webView/noticeDetail2`,
					})
				}else if(item.show=='1'){//推文链接
					uni.navigateTo({
						url: '/pagesD/webView/index?url='+encodeURIComponent(item.url)
					})
				}else if(item.type==2){//小程序地址
					// #ifdef MP-WEIXIN
					wx.navigateToMiniProgram({
						appId: 'wx911aceb2827f8f8c',
						shortLink: item.url,
						// envVersion: 'develop',//develop开发版  trial体验版  release正式版
					})
					// #endif
					// #ifndef MP-WEIXIN
					uni.showToast({title: '暂不支持',icon: 'error'})
					// #endif
				}
			},
			bannerClick(item){
				console.log(item,'-------146')
				if(item.show=='2'){//banner弹窗
					uni.navigateTo({
						url: item.url
					})
				}else if(item.type==1){//web链接
					uni.navigateTo({
						url: '/pagesD/webView/index?url='+encodeURIComponent(item.url)
					})
				}else if(item.type==2){//小程序地址
					// #ifdef MP-WEIXIN
					wx.navigateToMiniProgram({
						appId: 'wx911aceb2827f8f8c',
						shortLink: item.url,
						// envVersion: 'develop',//develop开发版  trial体验版  release正式版
					})
					// #endif
					// #ifndef MP-WEIXIN
					uni.showToast({title: '暂不支持',icon: 'error'})
					// #endif
				}
			},
			goDetail2(item){
				if([22,21].includes(item.configId)){
					let obj={22: '1',21:'3'};
					uni.navigateTo({
						url: `/pagesD/webView/examNotice2?type=${obj[item.configId]}`,
					})
				}else{
					!!item.configValue && uni.navigateTo({
						url: '/pagesD/webView/index?url='+encodeURIComponent(item.configValue)
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 0 36rpx
	}
	.tab{
		display: flex;
		margin-bottom: 18rpx;
		font-size: 28rpx;
		color: #333;
		.item{
			position: relative;
			padding-bottom: 14rpx;
			margin-right: 42rpx;
			&.on{
				color: #222;
				font-weight: 600;
				&::before{
					background-color: #3681F6;
				}
			}
			&::before{
				content: "";
				position: absolute;
				bottom: 0;
				left: 50%;
				width: 44rpx;
				height: 6rpx;
				margin-left: -22rpx;
				background-color: #fff;
				border-radius: 2rpx;
			}
		}
	}
	.banner{
		position: relative;
		height: 188rpx;
		margin-bottom: 30rpx;
		border-radius: 12rpx;
		.swiper{
			height: 100%;
		}
		.img,.swiper-item{
			width: 100%;
			height: 100%;
		}
	}
	.pro-list{
		.item{
			display: flex;
			padding: 32rpx 10rpx;
			border-top: 2rpx solid #E9E9E9;
		}
		.left{
			flex-shrink: 0;
			width: 176rpx;
			height: 176rpx;
			margin-right: 30rpx;
		}
		.img{
			width: 100%;
			height: 100%;
			border-radius: 4rpx;
		}
		.info{
			flex: 1;
			overflow: hidden;
			font-size: 28rpx;
			font-weight: 600;
			.title,.t1{
				margin-bottom: 8rpx;
			}
			.title{
				color: #222;
			}
			.t1{
				color: #D98847;
			}
			.price{
				color: #E05745;
				text-decoration: line-through;
				font-weight: 400;
			}
		}
	}
	.oldlist{
		padding: 32rpx 28rpx;
		line-height: 38rpx;
		font-weight: 500;
		.item{
			padding: 22rpx 24rpx 30rpx 40rpx;
			margin-bottom: 36rpx;
			background-color: #fff;
			box-shadow: 0rpx 0rpx 12rpx rgba(0,0,0,0.16);
			border-radius: 12rpx;
		}
		.title{
			margin-bottom: 14rpx;
			font-size: 30rpx;
			color: #303030;
		}
		.info{
			display: flex;
			justify-content: space-between;
			font-size: 24rpx;
			color: #9DA0A7;
		}
	}
	.oldlist1{
		.item{
			position: relative;
			padding: 22rpx 24rpx 22rpx 40rpx;
		}
		.title{
			display: flex;
		}
		.status{
			color: #999;
		}
		.status1{
			color: #6A8AE7;
		}
		.right{
			position: absolute;
			top: 50%;
			right: 30rpx;
			transform: translateY(-50%);
			display: flex;
		}
		.right-name{
			color: #999;
			font-size: 24rpx;
		}
		.iconfont{
			
		}
	}
	.search{
		position: relative;
		display: flex;
		align-items: center;
		height: 72rpx;
		margin: 0 12rpx 32rpx;
		font-size: 32rpx;
		input{
			flex: 1;
			height: 100%;
			padding-left: 94rpx;
			border-radius: 36rpx;
			background-color: #EBF2FF;
		}
		::v-deep .input-placeholder{
			color: #9D9D9D;
		}
		.icon{
			position: absolute;
			left: 44rpx;
			width: 28rpx;
			height: 28rpx;
			margin-right: 22rpx;
		}
	}
</style>
